package com.fr.lintcode;

public class Q1870 {
    /**
     * @param str:
     *            the string
     * @return: the number of substrings
     */
    public int stringCount(String str) {
        // Write your code here.
        if (str == null || str.length() == 0) {
            return 0;
        }
        int count = 0;
        int sum = 0;
        for (char c : str.toCharArray()) {
            if (c == '0') {
                count++;
            } else {
                if (count > 0) {
                    sum = sum + (count + 1) * count / 2;
                }
                count = 0;
            }
        }
        if (count > 0) {
            sum = sum + (count + 1) * count / 2;
        }
        return sum;
    }
}
